#include "addadmindialog.h"

#include "ui_addadmindialog.h"

#include <QSettings>
#include <QMessageBox>
#include <QStyle>

AddAdminDialog::AddAdminDialog(QWidget *parent)
    : QDialog(parent), ui(new Ui::AddAdminDialog) {
    ui->setupUi(this);

    this->setWindowTitle("添加新的管理员");
    // 设置窗口大小以及图标
    setFixedSize(256, 320);
    QStyle *style = QApplication::style();
    QIcon picture = style->standardIcon(QStyle::SP_DesktopIcon);
    setWindowIcon(picture);
}

AddAdminDialog::~AddAdminDialog() { delete ui; }

void AddAdminDialog::on_confirm_clicked() {
    if (ui->account->text().length() == 0 || ui->password->text().length() == 0) {
        QMessageBox::warning(this, "错误", "输入数据不能为空");
        return;
    }

    QSettings bookSettings("./admin.ini", QSettings::IniFormat);
    bookSettings.beginGroup("admin");
    bookSettings.setValue("account", ui->account->text());
    bookSettings.setValue("password", ui->password->text());
    bookSettings.endGroup();
    accept();
}

void AddAdminDialog::on_cancel_clicked() {
    reject();
}
